//
//  YXViewController.m
//  NewFeature
//
//  Created by mac on 15-3-29.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "YXViewController.h"
#import "YXFeatureView.h"
#import "YXModle.h"

@interface YXViewController ()<UIScrollViewAccessibilityDelegate>

@end

@implementation YXViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // 创建ScrollViewe及其frame
    UIScrollView *sc = [[UIScrollView alloc] init];
    sc.frame = self.view.bounds;
    [self.view addSubview:sc];
    sc.delegate = self;
  
    NSInteger count = 4;
    for (int i = 0; i < count; i ++) {
        // 创建分页
        YXFeatureView *fView = [YXFeatureView loadXib];
        // 设置每页的frame
        CGFloat W = self.view.bounds.size.width;
        CGFloat H = self.view.bounds.size.height;
        CGFloat Y = 0;
        CGFloat X = i *W;
        fView.frame = CGRectMake(X, Y, W, H);
        // 设置每页的tg
        fView.maxCount = count;
        fView.tg = i;
        // 加载每页相对应的图片
        YXModle *modle = [[YXModle alloc] init];
        modle.bkImage = [NSString stringWithFormat:@"guide%tuBackground", i + 1];
        modle.guiImge = [NSString stringWithFormat:@"guide%tu", i + 1];
        modle.larImage = [NSString stringWithFormat:@"guideLargeText%tu", i + 1];
        modle.smaImage = [NSString stringWithFormat:@"guideSmallText%tu", i + 1];
        fView.images = modle;
        // 添加分页到sc上
        [sc addSubview:fView];
    }
    // 设置scrollView想着属性
    // 设置滚动范围
    sc.contentSize = CGSizeMake(count *self.view.bounds.size.width, self.view.bounds.size.height);
    // 设置分页
    sc.pagingEnabled = YES;
    // 关闭弹簧
    sc.bounces = NO;
    // 关闭滚动条
    sc.showsHorizontalScrollIndicator = NO;
    
    
   
}


- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    // 设置滚动到了第几页
    int page = scrollView.contentOffset.x / self.view.frame.size.width;
    YXFeatureView *fv = scrollView.subviews[page];
    [fv startAnimation:YES];
  
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
